package com.amit.hibernate;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

public class Lab32 {

	public static void main(String[] args) {
		
		
		SessionFactory sessionfactory=Chibernateutil.getfactory();
		Session session=sessionfactory.openSession();
		Transaction tx=session.beginTransaction();
		
		System.out.println("1.All the contacts");
		
		List<Contact> clist1=session.getNamedQuery("JLCALLContacts").list();
		for(Contact c:clist1)
		{
			System.out.println(c.getContactId()+" "+c.getFirstName()+" "+c.getLastName()+" "+c.getEmail()+" "+c.getPhone()+" "+c.getDob()+" "+c.getStatus());
		}
		

		System.out.println("2.All Active the contacts");
		
		List<Contact> clist2=session.getNamedQuery("JLCActiveContacts")
		.setString("st", "active").list();
		for(Contact c:clist2)
		{
			System.out.println(c.getContactId()+" "+c.getFirstName()+" "+c.getLastName()+" "+c.getEmail()+" "+c.getPhone()+" "+c.getDob()+" "+c.getStatus());
		}
		
		

		System.out.println("3.Emails of  All the contacts");
		
		List<String> clist3=session.getNamedQuery("EmailsOfAllContacts").list();
		for(String c:clist3)
		{
			System.out.println(c);
		}
		
		
		
System.out.println("4.Emails,phones and status of the contacts");
		
		List<Object []> clist4=session.getNamedQuery("EmailsAndPhonesOfALLContacts").list();
		for(Object obj[]:clist4)
		{
			for(Object o:obj)
			{
			System.out.println(o+"\t");
			}
			System.out.println("");
		}
		
		tx.commit();
		session.close();

	}

}
